package com.topInterview;

public class leecode169 {
    public int majorElement(int[] arr) {
        int cand = 0;
        int hp = 0;
        for (int i = 0; i < arr.length; i++) {
            if (hp == 0) {
                cand = arr[i];
                hp = 1;
            } else if (arr[i] == cand) {
                hp++;
            } else {
                hp--;
            }
        }
        return cand;
    }
}
